import Taro, { Component } from '@tarojs/taro'
import { View, Text, Button } from '@tarojs/components'
import './auth.scss'

export default class Cart extends Component {

  constructor (props) {
    super(props)
    this.state = {
    }
  }
  componentWillMount () { }

  componentDidMount () {

  }

  componentWillUnmount () { }

  componentDidShow () { }

  componentDidHide () { }
  gtUserInfo (e) {
    if (e.detail.errMsg === 'getUserInfo:ok') {
      Taro.login({
        success (res) {
          if (res.code) {
            //发起网络请求
            console.log(res)
            console.log('登录成功')
          } else {
            console.log('登录失败！' + res.errMsg)
          }
        }
      })
    }
    Taro.navigateBack({ changed: true })
  }
  render () {

    return (
      <View className='auth'>
        <View className='basic_info'>
          <View className='avat'>
            <open-data type='userAvatarUrl'></open-data>
          </View>

          <open-data type='userNickName' lang='zh_CN'></open-data>
        </View>
        <Button className='auth_btn' open-type='getUserInfo' lang='zh_CN' onGetuserinfo={this.gtUserInfo}>授权登录</Button>
      </View>
    )
  }
}

